import React from "react";
import Reflux from "reflux";
import {LdhPage, LdhPageBody, LdhPageTable} from "@biz/PageCompnents";
import {PublicAction} from "@/base/BaseAction";

import {createAction} from "./Action";
import Store from "./Store";
import buildConfig from "./config";
import Search from "./biz/Search";

import "./style.less";
import {LdhStatusBar} from "../../../biz/PageCompnents";
import ConfirmWithdrawalModal from "./biz/ConfirmWithdrawalModal";

let Config = {};
const prefix = "shop-withdrawal-page"
export default class ShopWithdrawalPage extends Reflux.Component {
    constructor(props) {
        super(props);
        this.action = createAction();
        Config = buildConfig(this.action);
        this.store = new Store(props, Config, this.action);
    }

    componentDidMount() {
        this.search();
        if (window.isRoot) {
            PublicAction.allShopList(({voList = []}) => {
                this.setState({shopList: voList})
            });
        }
    }

    search() {
        let {so} = this.state;
        this.action.search(so);
    }


    componentWillUnmount() {
        this.action.unmount();
    }

    handleStatusChange(v){
        let {so} = this.state;
        so.status = v;
        so.searchByStatus=true;
        this.action.search(so);
    }
    render() {
        let {so, statusList=[]} = this.state;
        return <LdhPage className={prefix}>
            {window.isRoot && <Search store={this.state} action={this.action}/>}
            <LdhPageBody>
                <LdhStatusBar list={statusList} value={so.status} onChange={this.handleStatusChange.bind(this)}/>

                <LdhPageTable config={Config} store={this.state}></LdhPageTable>

            </LdhPageBody>
            {window.isRoot &&<ConfirmWithdrawalModal store={this.state} action={this.action}/>}
        </LdhPage>

    }


}
